package logic

import (
	"context"
	"fmt"
	"shop/model/mysql"
	"shop/shopclient"

	"shop/internal/svc"
	"shop/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseCareteListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseCareteListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseCareteListLogic {
	return &HouseCareteListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseCareteListLogic) HouseCareteList(in *shop.HouseCareteListRequest) (*shop.HouseCareteListResponse, error) {
	// todo: add your logic here and delete this line

	var hs []mysql.House
	mysql.DB.Order("created_at desc").Find(&hs)
	var houseCreateList []*shopclient.HouseCareteList
	for _, h := range hs {
		houseCreateList = append(houseCreateList, &shopclient.HouseCareteList{
			Image: h.Image,
			Title: h.Title,
			Price: float32(h.Price),
			Num:   int64(h.Num),
			Info:  h.Info,
		})
	}
	fmt.Println(houseCreateList)
	return &shop.HouseCareteListResponse{
		List: houseCreateList,
	}, nil
}
